<!--
 * @作者: kerwin
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .kerwin-modal{
            position: fixed;
            width: 200px;
            height: 200px;
            line-height: 200px;
            text-align: center;
            left:50%;
            top:50%;
            transform: translate(-50%,-50%);
            background-color: yellow;
        }
    </style>
</head>
<body>
    <!-- <div class="kerwin-modal">
        登录对话框
    </div> -->
    <button id="open">打开</button>
    <button id="close">关闭</button>
    <script>
        const Modal = (function(){
            let instance = null
            return function(){
                if(!instance){
                    instance = document.createElement("div")
                    instance.innerHTML = "登录对话框"
                    instance.className = "kerwin-modal"
                    instance.style.display = "none"
                    document.body.appendChild(instance)
                }
                return instance
            }
        })()
        
        document.querySelector("#open").onclick = function(){
            //创建modal
            const modal = Modal()    
            //显示modal
            modal.style.display = "block"
        }

        document.querySelector("#close").onclick = function(){
            //创建modal
            const modal = Modal()    
            //显示modal
            modal.style.display = "none"
        }
    </script>
</body>
</html>